#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

void solve()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        if(s[i] == '1'){
            a[i]++;
        }else{
            a[i]--;
        }
    }
    priority_queue<int> pq;
    for(int i = n - 2; i >= 0; i--) {
        a[i] += a[i + 1];
    }
    for(int i = 1; i < n; i++)pq.push(a[i]);
    int ans = 0, t = 0;
    while(!pq.empty()) {
        int x = pq.top();
        pq.pop();
        ans++;
        if(x <= 0) break;
        t += x;
        if(t >= k){
            break;
        }
    }
    if(t >= k) {
        cout << ans + 1 << endl;
    }else{
        cout << -1 << endl;
    }

}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}